<template>
  <div>
    <van-field label='名称' v-model='name'/>
    <van-field label='参数' v-model='params'/>
    选择分类
    <reply :data='cates'/>
    <van-button @click='add'>添加</van-button>
  </div>
</template>
<script>
import reply from './reply'

export default {
  components: {
    'reply': reply
  },
  data() {
    return {
      name: '',
      params: '',
      pid: 0,
      cates: {}
    }
  },
  methods: {
    add() {
      // 判断参数是否有值
      if (this.params) {
        this.params = JSON.stringify(this.params)
      }
      if (localStorage.getItem('pid')) {
        this.pid = localStorage.getItem('pid')
      }

      let data = {'name': this.name, 'pid': this.pid, 'params': this.params}
      this.axios.post('cateM', data).then(res => {
        this.getlist()
      })
    },
    //获取无限级分类
    getlist() {
      this.axios.get('cateM').then(res => {
        this.cates = {'id': 0, 'name': '333', 'son': res.data.list}
        console.log(res.data.list)
      })
    }

  },
  mounted() {
    this.getlist()
  },

}
</script>
<style lang="">

</style>
